//
//  DataBaseManager.h
//  QuickCure
//
//  Created by 马文星 on 16/5/2.
//  Copyright © 2016年 Demos. All rights reserved.
//  数据库管理工具（路径、创建数据库、打开、关闭、销毁数据库）

#import <Foundation/Foundation.h>
#import "FMDB.h"
#import "FMDatabaseQueue.h"


static NSString *_DatabaseDirectory;
static NSString * DatabaseDirectory() { //数据库文件夹
    
    if (!_DatabaseDirectory) {
        

        NSString *docDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        _DatabaseDirectory = [[docDirectory stringByAppendingPathComponent:[[NSProcessInfo processInfo] processName]] stringByAppendingPathComponent:@"Database"];
        
        NSFileManager *fileManager = [NSFileManager defaultManager];
        BOOL isDir;
        BOOL isExist = [fileManager fileExistsAtPath:_DatabaseDirectory isDirectory:&isDir];
        if (!isExist) {
            //创建文件夹的方法被搞错了
            [fileManager createDirectoryAtPath:_DatabaseDirectory withIntermediateDirectories:YES attributes:nil error:nil];
        }
    }
    return _DatabaseDirectory;
}

@interface DataBaseManager : NSObject


/** 队列 */
@property (nonatomic, strong) FMDatabaseQueue *databaseQueue;

/** 是否打开 */
@property (nonatomic, assign) BOOL isDatabaseOpened;

/** 数据库sqlite路径 */
@property (nonatomic, copy) NSString *writablePath;


/** 单例 */
+ (instancetype)sharedmanager;

/** 打开数据库 */
- (void)openDataBase;

/** 关闭数据库 */
- (void)closeDataBase;

/** 销毁数据库 */
- (void)releaseManager;

@end







